package Game.Objects;

import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;

import org.newdawn.slick.Image;
import org.newdawn.slick.SlickException;

import GUI.GuiManager;
import GUI.GuiMessenger;
import Game.GameHelper;
import Game.Buff.BuffManager;
import Screens.MyScreens.GameScreen;

// TODO: sound for use

/** Game object Altar class
 * @author Aikidos
 */
public class GOAltar extends GameObject {
	
	/** List of available buff class names */
	private List<String> _lstBuff = new ArrayList<String>();
	
	public GOAltar(ObjectManager objectManager) throws SlickException {
		super(objectManager, "Altar");
		
		setSprite(new Image("res/gfx/objects/altar.png"));
		
		_isCanBeUsed = true;
		
		// Add buff classes
		_lstBuff.add("Game.Buff.BuffHeal");
		_lstBuff.add("Game.Buff.BuffStrength");
		_lstBuff.add("Game.Buff.BuffMydriasis");
		_lstBuff.add("Game.Buff.DebuffPoison");
		_lstBuff.add("Game.Buff.DebuffZombie");
	}

	@Override
	public void use(GameObject user) throws SlickException,
			InstantiationException, IllegalAccessException,
			IllegalArgumentException, InvocationTargetException,
			NoSuchMethodException, SecurityException, ClassNotFoundException {
		
		// Get random
		Random rnd = GameHelper.getRandom();
				
		if (user.isPlayer()) {
			GOPlayer player = (GOPlayer)user;
			
			if (player.Magic > 0) {
				int subMagic = rnd.nextInt(player.Magic) + 1;
				player.Magic -= subMagic;
				
				// Show message
				GuiManager.getMessenger().addMessage("[yellow]" + getName() + "[/yellow] absorbed [cyan]" + subMagic + "[/cyan] magic");
				
				// Give random buff
				String buffClassName = _lstBuff.get(rnd.nextInt(_lstBuff.size()));
				Class.forName(buffClassName).getConstructor(BuffManager.class).newInstance(player.getBuffManager());
			}
		}
	}
	
	

}
